home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Macintosh Tracker 1.20 / source / Tracker Client Folder / Core 18⁄March⁄1994 / CHScrollBar.c < prev    next >
Encoding:
Text File  |  1993-06-06  |  10.3 KB  |  235 lines  |  [TEXT/KAHL]

  1.  
  2. void            CHScrollBar::DoMouseDown(MyEventRec Event)
  3.     {
  4.         long                Length;
  5.         LongPoint        MouseLoc;
  6.         MyBoolean        OutOfRange;
  7.         short                XorPosition;
  8.         MyBoolean        ImageXored;
  9.  
  10.         CurrentOperation = FindPart(MyGlobalToLocal(Event.Where));
  11.         switch (CurrentOperation)
  12.             {
  13.                 case mLeftOne:
  14.                     if (HScrollable && Enabled)
  15.                         {
  16.                             do{
  17.                                     RedrawHBar();
  18.                                     if (CurrentOperation == mLeftOne)
  19.                                         {
  20.                                             Owner->Hook(HScrollLeftOne,0,0);
  21.                                         }
  22.                                     CurrentOperation = FindPart(MyGlobalToLocal(GetLongMouseLoc()));
  23.                                     if (CurrentOperation != mLeftOne)
  24.                                         {
  25.                                             CurrentOperation = mNone;
  26.                                         }
  27.                                     RelinquishCPU();
  28.                                     SendIdleToAll();
  29.                                 } while (WaitMouseUp());
  30.                             CurrentOperation = mNone;
  31.                             RedrawHBar();
  32.                         }
  33.                     break;
  34.                 case mLeftPage:
  35.                     if (HScrollable && Enabled)
  36.                         {
  37.                             do{
  38.                                     RedrawHBar();
  39.                                     if (CurrentOperation == mLeftPage)
  40.                                         {
  41.                                             Owner->Hook(HScrollLeftPage,0,0);
  42.                                         }
  43.                                     CurrentOperation = FindPart(MyGlobalToLocal(GetLongMouseLoc()));
  44.                                     if (CurrentOperation != mLeftPage)
  45.                                         {
  46.                                             CurrentOperation = mNone;
  47.                                         }
  48.                                     RelinquishCPU();
  49.                                     SendIdleToAll();
  50.                                 } while (WaitMouseUp());
  51.                             CurrentOperation = mNone;
  52.                             RedrawHBar();
  53.                         }
  54.                     break;
  55.                 case mRightOne:
  56.                     if (HScrollable && Enabled)
  57.                         {
  58.                             do{
  59.                                     RedrawHBar();
  60.                                     if (CurrentOperation == mRightOne)
  61.                                         {
  62.                                             Owner->Hook(HScrollRightOne,0,0);
  63.                                         }
  64.                                     CurrentOperation = FindPart(MyGlobalToLocal(GetLongMouseLoc()));
  65.                                     if (CurrentOperation != mRightOne)
  66.                                         {
  67.                                             CurrentOperation = mNone;
  68.                                         }
  69.                                     RelinquishCPU();
  70.                                     SendIdleToAll();
  71.                                 } while (WaitMouseUp());
  72.                             CurrentOperation = mNone;
  73.                             RedrawHBar();
  74.                         }
  75.                     break;
  76.                 case mRightPage:
  77.                     if (HScrollable && Enabled)
  78.                         {
  79.                             do{
  80.                                     RedrawHBar();
  81.                                     if (CurrentOperation == mRightPage)
  82.                                         {
  83.                                             Owner->Hook(HScrollRightPage,0,0);
  84.                                         }
  85.                                     CurrentOperation = FindPart(MyGlobalToLocal(GetLongMouseLoc()));
  86.                                     if (CurrentOperation != mRightPage)
  87.                                         {
  88.                                             CurrentOperation = mNone;
  89.                                         }
  90.                                     RelinquishCPU();
  91.                                     SendIdleToAll();
  92.                                 } while (WaitMouseUp());
  93.                             CurrentOperation = mNone;
  94.                             RedrawHBar();
  95.                         }
  96.                     break;
  97.                 case mHBox:
  98.                     if (HScrollable && Enabled)
  99.                         {
  100.                             if ((Event.Modifiers & optionKey) != 0)
  101.                                 {
  102.                                     short        OldMouseLoc = -32767;
  103.  
  104.                                     ImageXored = False;
  105.                                     /* setting up drawing environment */
  106.                                     SetUpPort();
  107.                                     Length = PageRightZoneExt.x + PageLeftZoneExt.x;
  108.                                     do{
  109.                                             static LongPoint    HXorBoxExt = {16,14};
  110.  
  111.                                             /* removing any image already there */
  112.                                             do
  113.                                                 {
  114.                                                     MouseLoc = MyGlobalToLocal(GetLongMouseLoc());
  115.                                                     RelinquishCPU();
  116.                                                     SendIdleToAll();
  117.                                                 } while ((MouseLoc.x - 16 - 8 == OldMouseLoc) && WaitMouseUp());
  118.                                             SetUpPort();
  119.                                             Window->ResetPen();
  120.                                             Window->SetPenMode(srcXor);
  121.                                             Window->SetPattern(dkGray);
  122.                                             if (ImageXored)
  123.                                                 {
  124.                                                     Window->LFrameRect(LongPointOf(XorPosition + 16,
  125.                                                         Extent.y - 16 + 1),HXorBoxExt);
  126.                                                     ImageXored = False;
  127.                                                 }
  128.                                             /* finding new image position */
  129.                                             OutOfRange = False;
  130.                                             OldMouseLoc = MouseLoc.x - 16 - 8;
  131.                                             XorPosition = OldMouseLoc;
  132.                                             if ((MouseLoc.y < Extent.y - 16 - 24)
  133.                                                 || (MouseLoc.y > Extent.y + 24))
  134.                                                 {
  135.                                                     OutOfRange = True;
  136.                                                 }
  137.                                             if (XorPosition < 0)
  138.                                                 {
  139.                                                     XorPosition = 0;
  140.                                                 }
  141.                                             if (XorPosition > Length)
  142.                                                 {
  143.                                                     XorPosition = Length;
  144.                                                 }
  145.                                             /* putting new image position */
  146.                                             if (!OutOfRange)
  147.                                                 {
  148.                                                     Window->LFrameRect(LongPointOf(XorPosition + 16,
  149.                                                         Extent16;
  150.         OneLeftZoneExt.x = 16;
  151.         OneRightZoneTL.y = Extent.y - 16;
  152.         OneRightZoneTL.x = Length - 16;
  153.         OneRightZoneExt.y = 16;
  154.         OneRightZoneExt.x = 16;
  155.         if (NumCells <= 1)
  156.             {
  157.                 if (CellIndex == 0)
  158.                     {
  159.                         HScrollable = False;
  160.                         HScrollZoneTL.y = Extent.y - 16;
  161.                         HScrollZoneTL.x = 16;
  162.                         HScrollZoneExt.y = 16;
  163.                         HScrollZoneExt.x = Length - 16 - 16;
  164.                     }
  165.                  else
  166.                     {
  167.                         NumCells = -NumCells;
  168.                         goto TryAgainPoint;
  169.                     }
  170.             }
  171.          else
  172.             {
  173.              TryAgainPoint:
  174.                 HScrollable = True;
  175.                 if (NumCells == 1)
  176.                     {
  177.                         if (CellIndex < 0)
  178.                             {
  179.                                 BoxPos = 0;
  180.                             }
  181.                          else
  182.                             {
  183.                                 BoxPos = Length - 3*16;
  184.                             }
  185.                     }
  186.                  else
  187.                     {
  188.                         BoxPos = ((Length - 3*16)
  189.                             * ((long double)CellIndex) / ((long double)(NumCells - 1)));
  190.                         if (BoxPos < 0)
  191.                             {
  192.                                 BoxPos = 0;
  193.                             }
  194.                         if (BoxPos > Length - 3*16)
  195.                             {
  196.                                 BoxPos = Length - 3*16;
  197.                             }
  198.                     }
  199.                 PageLeftZoneTL.y = Extent.y - 16;
  200.                 PageLeftZoneTL.x = 16;
  201.                 PageLeftZoneExt.y = 16;
  202.                 PageLeftZoneExt.x = BoxPos;
  203.                 HScrollZoneTL.y = Extent.y - 16 + 1;
  204.                 HScrollZoneTL.x = BoxPos + 16;
  205.                 HScrollZoneExt.y = 14;
  206.                 HScrollZoneExt.x = 16;
  207.                 PageRightZoneTL.y = Extent.y - 16;
  208.                 PageRightZoneTL.x = BoxPos + 16 + 16;
  209.                 PageRightZoneExt.y = 16;
  210.                 PageRightZoneExt.x = (Length - 3*16) - BoxPos;
  211.             }
  212.     }
  213.  
  214.  
  215. void            CHScrollBar::SetPosition(long NewCellIndex, long NewNumCells)
  216.     {
  217.         CellIndex = NewCellIndex;
  218.         NumCells = NewNumCells;
  219.         RecalcScrollRects();
  220.         if ((!Suspended) && Enabled)
  221.             {
  222.                 RedrawHBar();
  223.             }
  224.     }
  225.  
  226.  
  227. void            CHScrollBar::RecalcLocations(LongPoint EnclosureVisRectStart,
  228.                         LongPoint EnclosureVisRectExtent, LongPoint EnclosureOrigin)
  229.     {
  230.         inherited::RecalcLocations(EnclosureVisRectStart,EnclosureVisRectExtent,
  231.             EnclosureOrigin);
  232.         RecalcScrollRects();
  233.     }
  234.